/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package entity;

import java.io.Serializable;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.OneToOne;
import java.util.*;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import type.CustomerType;
import type.UserTitle;

/**
 *
 * @author Andy
 */
@Entity(name = "Customer")
public class CustomerEntity extends PersonEntity implements Serializable {

    @OneToOne
    private CustomerAccountEntity customerAccount;
    @ManyToOne
    private SystemUserEntity customerExecutive = new SystemUserEntity();
    @OneToMany(targetEntity = SalesQuotationEntity.class, mappedBy = "customer")
    private Collection<SalesQuotationEntity> salesQuotations = new ArrayList<SalesQuotationEntity>();
    @OneToMany(targetEntity = SalesInquiryEntity.class, mappedBy = "customer")
    private Collection<SalesInquiryEntity> salesInquiries = new ArrayList<SalesInquiryEntity>();
    @OneToMany(targetEntity = SalesOrderEntity.class, cascade = {CascadeType.ALL}, mappedBy = "customer")
    private Collection<SalesOrderEntity> salesOrder = new ArrayList<SalesOrderEntity>();
    @OneToMany(targetEntity = PurchaseOrderEntity.class, mappedBy = "customer")
    private Collection<PurchaseOrderEntity> purchaseOrder = new ArrayList<PurchaseOrderEntity>();
    private boolean blackListed;
    private String companyName;
    private String jobTitle;
    private CustomerType customerType;

    public CustomerEntity() { 
        super();
        setBlackListed(false);
    }

    public CustomerType getCustomerType() {
        return customerType;
    }

    public void setCustomerType(CustomerType customerType) {
        this.customerType = customerType;
    }

    public String getCompanyName() {
        return companyName;
    }

    public void setCompanyName(String companyName) {
        this.companyName = companyName;
    }

    public String getJobTitle() {
        return jobTitle;
    }

    public void setJobTitle(String jobTitle) {
        this.jobTitle = jobTitle;
    }

    public CustomerAccountEntity getCustomerAccount() {
        return customerAccount;
    }

    public void setCustomerAccount(CustomerAccountEntity customerAccount) {
        this.customerAccount = customerAccount;
    }

    public SystemUserEntity getCustomerExecutive() {
        return customerExecutive;
    }

    public void setCustomerExecutive(SystemUserEntity customerExecutive) {
        this.customerExecutive = customerExecutive;

    }

    public boolean isBlackListed() {
        return blackListed;
    }

    public void setBlackListed(boolean blackListed) {
        this.blackListed = blackListed;
    }

    public Collection<SalesQuotationEntity> getSalesQuotations() {
        return salesQuotations;
    }

    public void setSalesQuotations(Collection<SalesQuotationEntity> salesQuotations) {
        this.salesQuotations = salesQuotations;
    }

    public Collection<SalesInquiryEntity> getSalesInquiries() {
        return salesInquiries;
    }

    public void setSalesInquiries(Collection<SalesInquiryEntity> salesInquiries) {
        this.salesInquiries = salesInquiries;
    }

    public Collection<SalesOrderEntity> getSalesOrder() {
        return salesOrder;
    }

    public void setSalesOrder(Collection<SalesOrderEntity> salesOrder) {
        this.salesOrder = salesOrder;
    }

    public Collection<PurchaseOrderEntity> getPurchaseOrder() {
        return purchaseOrder;
    }

    public void setPurchaseOrder(Collection<PurchaseOrderEntity> purchaseOrder) {
        this.purchaseOrder = purchaseOrder;
    }
    
    @Override
    public String toString() {
        return this.getFirstName()+" "+this.getLastName()+" [Id= "+this.getId() + "]";
    }
    
    public String rootToString() {
        return "CustomerEntity{" + "customerAccount=" + customerAccount + ", customerExecutive=" + customerExecutive + ", salesQuotations=" + salesQuotations + ", salesInquiries=" + salesInquiries + ", salesOrder=" + salesOrder + ", purchaseOrder=" + purchaseOrder + ", blackListed=" + blackListed + ", companyName=" + companyName + ", jobTitle=" + jobTitle + ", customerType=" + customerType + '}';
    }
    
    public boolean getHasAccount(){
        return customerAccount!=null;
    }
}
